package com.hippy.erya.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hippy.erya.entity.MemberDO;
import com.hippy.erya.mapper.MemberMapper;
import com.hippy.erya.query.BaseQueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> {

    @Autowired
    private MemberMapper memberMapper;

    public Page<MemberDO> queryByPage(long currentPage, int limit, String memberName, String memberGrade) {
        Page<MemberDO> page = new Page<>(currentPage, limit);
        QueryWrapper<MemberDO> queryWrapper = BaseQueryWrapper.buildQuery();
        if (StringUtils.isNotBlank(memberName)) {
            queryWrapper.like("MEMBER_NAME", memberName);
        }
        if (StringUtils.isNotBlank(memberGrade)) {
            queryWrapper.eq("MEMBER_GRADE", memberGrade);
        }
        Page<MemberDO> pageResult = memberMapper.selectPage(page, queryWrapper);
        pageResult.getRecords().forEach(BaseQueryWrapper::outputMessage);
        return pageResult;
    }
}
